﻿using DDDSystem.Domain.Entities;
using DDDSystem.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;

namespace DDDSystem.EntityFrameworkCore.Controllers;

[ApiController]
[Route("[controller]")]
public class BasicDictionaryController : ControllerBase
{
    private PSIDbContext _context;

    public BasicDictionaryController(PSIDbContext context)
    {
        _context = context;
    }

    [HttpGet]
    public IEnumerable<BasicDictionary> Get()
    {
        using (_context)
        {
            //使用ef添加一条数据
            BasicDictionary basicDictionary = new BasicDictionary();
            basicDictionary.ID = Guid.NewGuid();
            basicDictionary.Code = "1";
            basicDictionary.Name = "2";
            basicDictionary.Sort = 0;
            basicDictionary.Type = Domain.Shared.BasicDictionaryType.WarehouseType;
            basicDictionary.PinYinCode = "*";
            basicDictionary.Status = Domain.Shared.BasicDictionaryStatus.Valid;

            _context.BasicDictionaries.Add(basicDictionary);
            _context.SaveChanges();

            var items = _context.BasicDictionaries.Where(b => true).ToList();

            return items;
        }
    }
}

